package com.fbinggun.fbinggunutil.statistics.command;

import com.fbinggun.fbinggunutil.FBinggunUtil;
import com.fbinggun.fbinggunutil.command.ACommand;
import com.fbinggun.fbinggunutil.command.MainCommand;
import com.fbinggun.fbinggunutil.statistics.PlayerStatistics;
import com.fbinggun.fbinggunutil.statistics.StatisticsAPI;
import com.fbinggun.fbinggunutil.statistics.StatisticsInfo;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

public class get extends ACommand {
    public get(MainCommand mainCommand) {
        super(mainCommand);
    }

    @Override
    public String getPresentation() {
        return "&e/"+getMainCommand().getCmd()+" "+getId()+" [玩家名] [id] &f查询玩家此项统计值";
    }
    @Override
    public boolean isOp() {
        return true;
    }

    @Override
    public String getPermission() {
        return null;
    }

    @Override
    public String getId() {
        return "get";
    }

    @Override
    public boolean run(CommandSender sender, String[] args) {
        if(args.length==3){
            OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
            String id =args[2];
            if(id.equalsIgnoreCase("*")){
                PlayerStatistics statistics= FBinggunUtil.plugin.getStatistMain().getStatApi().getPlayerStatistics(player);
                if(statistics.getData()!=null){
                    for(StatisticsInfo info:statistics.getData().values()){
                        getPlugin().sendPlayerMsg(sender, "&a玩家 &f" + player.getName() + " &a的 " + info.getId() + " 统计值为 &b" + info.getPlaceholder());
                    }
                    return false;
                }

            }else {
                getPlugin().sendPlayerMsg(sender, "&a玩家 &f" + player.getName() + " &a的 " + id + " 统计值为 &b" + FBinggunUtil.plugin.getStatistMain().getStatApi().getPlaceholder(player, id));
            }
        }
        return false;
    }

    @Override
    public List<String> getTAB(int l, CommandSender sender,String[] args) {
        List<String> list= super.getTAB(l, sender,args);
        if(l==2){
            for(Player player:Bukkit.getOnlinePlayers()){
                list.add(player.getName());
            }
        }
        if(l==3){
            OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
            list.add("*");
            PlayerStatistics statistics= FBinggunUtil.plugin.getStatistMain().getStatApi().getPlayerStatistics(player);
            if(statistics.getData()!=null){
                list.addAll(statistics.getData().keySet());
            }
        }
        return list;
    }

    @Override
    public boolean isPlayer() {
        return false;
    }
}
